﻿var messageController = {
    message: $("#message"),
    messageData: {
        processing: { "text": "Processing...!", "type": "info" },
        process_complete: { "text": "Process complete!", "type": "success" },
        process_error: { "text": "Some errors occurred while processing!", "type": "warning" },
        "invalid_id": { "text": "Invalid ID!", "type": "danger" },
        "invalid_password": { "text": "Invalid password!", "type": "danger" },
        "type_password": { "text": "Type your password!", "type": "danger" },
        "same_password": { "text": "New password must be different with old password!", "type": "danger" },
        "no_matched_newpass": { "text": "New password and confirm password do not match!", "type": "danger" },
        "no_matched_data": { "text": "No matched data!", "type": "warning" },
        "loading": { "text": "Loading data...!", "type": "info" },
        "load_complete": { "text": "Load complete!", "type": "success" },
        "load_error": { "text": "Some errors occurred while loading! Try again!", "type": "warning" },
        "saving": { "text": "Saving data...!", "type": "info" },
        "save_success": { "text": "Save successfully!", "type": "success" },
        "save_fail": { "text": "Failure to save! Try again!", "type": "danger" },
        "printer_loading": { "text": "Printers are loading...!", "type": "info" },
        "printer_wait": { "text": "Please wait a few seconds before clicking Print button again!", "type": "info" },
        "cancel_request": { "text": "Request is canceled!", "type": "info" },
        "no_patient_folder": { "text": "No patient's image folder!", "type": "warning" },
        "no_file_folder": { "text": "No patient's image file in folder!", "type": "warning" },
        "no_matched_file": { "text": "No matched file!", "type": "warning" },
        "get_meta": { "text": "Getting metadata!", "type": "info" },
        "image_loading": { "text": "Please wait a few seconds while images are loading!", "type": "info" },
        "no_image": { "text": "No image in file!", "type": "warning" },
        "reset_pass_success": { "text": "Reset successfully!", "type": "success" },
        "reset_pass_fail": { "text": "Failure to reset! Try again!", "type": "danger" },
        "exist_socialid": { "text": "This Social ID is existing!", "type": "danger" },
        "type_userName": { "text": "Type User Name!", "type": "danger" },
        "type_userAddress": { "text": "Type User Address!", "type": "danger" },
        "select_birthday": { "text": "Invalid Birthday! Note: Year must from 1753 to 9999!", "type": "danger" },
        "invalid_year": { "text": "Invalid Year! Note: Year must from 1753 to 9999!", "type": "danger" },
        "invalid_phone": { "text": "Invalid Phone Number!", "type": "danger" },
        "not_accepted": { "text": "Request isn't accepted!", "type": "danger" }
    },
    displayMessage: function (state) {
        switch(state){
            case 0:
                this.message.stop(true, true).fadeOut(3000);
                break;
            case 1: 
                //this.message.stop(true, true).css({
                //    "display": "block"
                //});
                this.message.stop().fadeIn(1);
                break;
            case 2:
                //this.message.stop(true, true).css({
                //    "display": "block"
                //});
                this.message.stop().fadeIn(1);
                this.message.stop(true, true).fadeOut(3000);
                break;
        };
    },
    messageContent: $("#messageContent"),
    setMessageContent: function (data) {
        //alert(data);
        this.messageContent.attr({
            "class": "alert alert-" + this.messageData[data].type
        });
        this.messageContent.text(this.messageData[data].text);
    },
    setMessagePosition: function(){
        this.message.css({
            "top": $(window).height() / 2 - 100,
            "left": $(window).width() / 2 - 100
        });
    },
    processing: function (data) {
        this.setMessageContent(data);
        this.displayMessage(1);
    },
    processComplete: function (data) {
        this.setMessageContent(data);
        this.displayMessage(0);
    },
    toggleMessage: function (data) {
        this.setMessageContent(data);
        this.displayMessage(2);
    }
};
$(function () {
    messageController.setMessagePosition();
    $(window).on("resize", function () {
        messageController.setMessagePosition();
    });
    //alert(window.innerWidth + " " + window.innerHeight + " " + window.outerWidth + " " + window.outerHeight + $(window).width() + " " + $(window).height());
});